# 导入模块
import clr
import sys
import os
# 加载dll动态库
clr.AddReference('System.Collections')
clr.AddReference('PGMHelper')
clr.AddReference('NPOI.Helper')
clr.AddReference('HystereticBasic')
# 导入CLR相关模块
from System.Collections.Generic import List
from System import Single
from System import Tuple
from System.Collections.Generic import Dictionary
import numpy as np
import HystereticBasic

# py列表转C#列表
def changeToSingleList(list):
    # 初始化C#列表
    singleList=List[Single]()
    # 遍历py列表
    for each in list:
        singleList.Add(each)
    # 返回C#列表
    return singleList

# 滞回文件所在路径
filePath= "C:\Users\SCUT\Desktop\新建文件夹\1.txt"
# 是否过滤滞回环
isFilter =True
# 骨架曲线是否位移最大点做为骨架
isDisp = True
# 通过文件获得滞回数据
dataObj=HystereticBasic.BasicData(filePath, 0, isDisp, isFilter)

# 每个滞回环的最大位移
histroy = dataObj.CircleSet.GetLoadingHistory()
# 获得累积耗能面积
energyList = dataObj[HystereticBasic.DataType.Energy]
# 获得刚度退化系数
sDegradationList = dataObj[HystereticBasic.DataType.DegradCoe]


# 获得每个滞回环
circleList = dataObj.CircleSet.GetCircleList(isFilter)
# 遍历滞回环
for circle in circleList:
    # 滞回环的最大、最小位移点，最大、最小承载力点
    dispMaxPtr = circle.DispMaxPoint
    dispMinPtr = circle.DispMinPoint
    forceMaxPtr = circle.ForceMaxPoint
    forceMinPtr = circle.ForceMinPoint
    # 通过点获得对应的位移和变形
    dispMax = dispMaxPtr.Disp
    forceMax = forceMaxPtr.Force
    # 滞回环面积
    A = circle.GetA()

# 骨架曲线
skeleton = dataObj.SkeletonCurveObj
# 获得正向 及负向的骨架曲线
posSkeleton = skeleton.GetHalfSkeletonCurveObj(True)
negSkeleton = skeleton.GetHalfSkeletonCurveObj(False)
# 可对骨架曲线位移对象进行缩放
negSkeleton.DispAmplitude(-1)
negSkeleton.ForceAmplitude(-1)
# 遍历骨架数据点
for i in range(posSkeleton.Count):
    prt = posSkeleton[i]
# 骨架曲线位移散点
dispSkeletonList = negSkeleton.Disps
forceSkeletonList = negSkeleton.Forces

# 延性系数计算
obj = HystereticBasic.DuctilityData(posSkeleton)
# 定义极限状态下的承载力退化系数、Park系数
obj.SetDuctilityFactor(0.9, 0.7)
# 获得对应方法下的延性系数值
factor = obj.GetDuctilityFactor(HystereticBasic.DuctilityMethod.Energy)


